import $service from '../../../../service.js';
var doctor_id;
var that;
var page=1;
const app = getApp()
Page({
    data:{
       active : "1",
       noticeList :[],
       loadingText: '',
       loadingType: true,
       num:0,
       num2:0
    },
    onLoad(e) {
    },
    onShow() {
        page = 1;
        that = this.data;
        this.getNewsList();
    },
    onPullDownRefresh() {
        page = 1;
        this.setData({
            loadingText: '加载更多'
        })
        this.getNewsList();
        wx.stopPullDownRefresh()
    },
    onReachBottom: function() {
        if (that.loadingType == true) {
            page++
            this.getNewsList(); 
        } else {
            this.setData({
                loadingText: '没有更多了'
            })
        }
    },
    loading(){
        if (that.loadingType == true) {
            page++
            this.getNewsList(); 
        } else {
            this.setData({
                loadingText: '没有更多了'
            })
        }
    },
    getNewsList() {
        let params = {
            "current": page,
            "size": 10,
            "noticeType": that.active
          }
        app.http.getNewsList(params, true).then(res => {
            let data = $service.deepClone(res.data.list);
            if (page == 1) {
                that.loadingText = '';
                that.noticeList = data;
            } else {
                if (data.length <= 0) {
                    that.loadingType = false;
                    that.loadingText = '没有更多了';
                } else {
                    for (var i = 0; i < data.length; i++) {
                        that.noticeList.push(data[i]);
                        that.loadingText = '加载更多';
                    }
                }
            }
            this.setData({
                noticeList: that.noticeList,
                loadingText: that.loadingText,
                loadingType: that.loadingType,
            })
        }).catch(err => {
            $service.showToast(err.msg);
        })
    },
    tapactive(e){
        var index = e.currentTarget.dataset.index;
        page = 1;
        this.setData({
            active : index
        })
        this.getNewsList();
    },
    gatoindex_news_details(e){
      var index = e.currentTarget.dataset.index;
      $service.openPage('/pages/user_side/index/index_health_guidance/index_health_guidance?id=' + this.data.noticeList[index].noticeJoin + '&type=4')
    }
})